﻿@using Utils;
@model WebUI.Models.JobPayLoggedInWithCreditsViewModel
@{
    ViewBag.Title = "Pay Your Listing - JuicyBasket";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h1>Pay Your Listing</h1>
<div class="mainSection">
    <div class="wizard-title">
        <div class="wizard-step">1. Create a Job Listing</div>
        <div class="wizard-sp">»</div>
        <div class="wizard-step">2. Preview</div>
        <div class="wizard-sp"> »</div>
        <div class="wizard-step active">3. Pay</div>
        <div class="clear"></div>
    </div>
    <div class="clear"></div>

    @if (Model.Job == null || Model.Co == null || Model.Job.JobID <= 0 || Model.Co.CoID <= 0)
    { 
        <div class="null-message">
	        <h2>You have no job to pay, please <a href="/job/post">create a job listing</a> first</h2>
        </div>
    }
    else
    {
        <div class="mainCol jp">
            @using (Html.BeginForm("GoPaymentForLoggedInWithCredits", "Co", new {JobToken = Model.Job.JobToken}, FormMethod.Post, new { ID = "payment-form" }))
            {
                int left = Model.Co.JobCredits - 1;
                <div class="spacer"></div>
                <div class="des">You currently have <strong>@Model.Co.JobCredits</strong> job credits left, and <strong>1 job credit</strong> will be taken for publishing this listing. You will have <strong>@left</strong> job credits left after publishing this listing. Would you like to publish it?</div>
                <div class="clear"></div>
                <div class="largespacer"></div>
                <div class="largespacer"></div>
                <div class="tabsbottom"></div>
                <div class="fr">
                    <a class="gray-submit" href="/job/preview?jobtoken=@Model.Job.JobToken">← Preview your listing</a>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="submit" id="submit-button" name="submit-button" value="Yes, publish this listing →" class="blue-submit" />
                </div>
                <div class="smallspacer"></div>
                <div class="fr" id="processingHint">
                    <img src="/content/images/spinnerlg.gif"/><div>&nbsp; Processing...</div>
                </div>
            }
        </div>
        <div class="sideCol">
            <div class="spacer"></div>
            
        </div>
    }
    <div class="clear"></div>
</div>

@section FooterContent
{
    <script type="text/javascript" src="@Url.StaticFile("~/content/jquery.form.js")"></script>
    <script type="text/javascript">
        $(function () {
            //ajax submit payment form
            $("#payment-form").ajaxForm({
                beforeSubmit: function (a, f, o) {
                    //alert("before");
                },
                dataType: 'json',
                success: ProcessForm,
                error: function (request, status, errorThrown) {     
                    return false;
                }
            });
        });

        function ProcessForm(data) {
            JsonResultHandler.Success(data);
        }
    </script>
}